#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
    string a,b,c,d;
    cin>>a>>b>>c>>d;
    char t1,t2;
    int i=0,flag=0;
    int minute;
    while(i<a.size()&&i<b.size()){
        if(flag==0&&a[i]==b[i]&&a[i]>='A'&&a[i]<='G'){
            t1=a[i];
            flag=1;
        }else if(flag==1&&a[i]==b[i]&&((a[i]>='A'&&a[i]<='N')||isdigit(a[i]))){
            t2=a[i];
            break;
        }
        i++;   
    }
    int len=(c.size()>d.size())?d.size():c.size();
    for(int j=0;j<len;j++){
        if(c[j]==d[j]&&isalpha(d[j])){
            minute=j;
            break;
        }
    }
    string week[7]={"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    int day=t1-'A';
    cout<<week[day]<<" ";
    int hh=isalpha(t2)?t2-'A'+10:t2-'0';
    if(hh<10) cout<<"0"<<hh<<":";
    else cout<<hh<<":";
    if(minute<=9) cout<<"0"<<minute;
    else cout<<minute;
}
